<?php
declare (strict_types = 1);

namespace app\controller;
use think\facade\Db;
use think\Collection;
use think\Request;

class Readdata
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {

        //显示全部行数据，不方便，在后端处理好
        // $rs=Db::name('temperature')->order('id','desc')->limit(10)->select();
        // //$rs=Db::query('select date,time,temperature from temperature limit 5 order by id desc');
        // return json($rs);

        //采用处理好的结构：{'time':['12:20','12:40'...],"temp":[12.3,23.4...]}
        $today= request()->param('today');
        $temps=Db::name('temperature')->where('date='.'\''.$today.'\'')->select();
        $timearr=array();
        $temparr=array();
        $i=0;
        foreach($temps as $temp){
            $temparr[$i]=$temp['temperature'];
            $timearr[$i]=substr($temp['time'],0,5);
            $i++;
        }

        return json(["temp"=>$temparr,"time"=>$timearr]);

    }

   
}
